package com.zjhn.ds.utils;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zjhn.ds.domain.dto.pc.WorkShopStationDto;
import com.zjhn.ds.domain.entity.jlw.Station;
import com.zjhn.ds.domain.vo.EquipmentVo;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @BelongsProject: ds_jlw
 * @BelongsPackage: com.zjhn.ds.utils
 * @Author: sxt
 * @CreateTime: 2023-09-12  16:42
 * @Description:
 * @Version: 1.0
 */
@Component
public class EntityTransformUtil {

    @Resource
    private CommonUtil commonUtil;

    /**
     * Station实体类转为 WorkShopStationDto
     * @param stationPage
     * @return
     */
    public IPage<WorkShopStationDto> workshopStationDtoChange(IPage<Station> stationPage) {
        IPage<WorkShopStationDto> convert = stationPage.convert(c -> {
            WorkShopStationDto res = WorkShopStationDto.builder()
                    .stationId(c.getId())
                    .stationName(c.getStationName())
                    .stationCode(c.getStationCode())
                    .workshop(commonUtil.getWorkshopById(c.getWorkshopId()))
                    .build();
            String equipmentId = commonUtil.getBindInfoById(c.getId());
            if (com.baomidou.mybatisplus.core.toolkit.StringUtils.isNotBlank(equipmentId)) {
                EquipmentVo equipmentVo = commonUtil.getEquipmentById(equipmentId);
                res.setEquipmentType(commonUtil.getEquipmentTypeById(equipmentVo.getEquipmentTypeId()));
                res.setModelName(commonUtil.getModelById(equipmentVo.getModelId()).getModelName());
            }
            return res;
        });

        return convert;
    }
}
